package com.github.llyb120.mugen;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class AnalyzedMethod {
    //注解类
    Class clz;
    //注解类实例
    Object source;
    Method method;
    Object instance;

    public Object invoke(Object... args) {
//        Object[] args = null;
               /**
                Arrays.stream(method.getParameters())
                .map(e -> {
                    if (e.getType() == PluginChainContext.class) {
                        return context;
                    } else {
                        return null;
                    }
                })
                .toArray();
                **/
        try {
            return method.invoke(instance, args);
        } catch (IllegalAccessException | InvocationTargetException e) {
            throw new MethodInvokeException(e);
        }
    }

}
